package com.lagou.goods.controller;


import com.lagou.common.pojo.Goods;
import com.lagou.common.pojo.GoodsDTO;
import com.lagou.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    /**
     * 通过商品ID查询商品信息
     * @param id
     * @return
     */
    @GetMapping("/query/{id}")
    public Goods queryById(@PathVariable Integer id){
        return goodsService.queryById(id);
    }

    /**
     * 通过商品ID删除商品信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Integer deleteById(@PathVariable Integer id){return  goodsService.deleteById(id);}

    /**
     * 编辑商品信息
     * @param goods
     * @return
     */
    @PutMapping("/update")
    public Integer updateById(@RequestBody Goods goods){return goodsService.updateById(goods);}
    /*
     * 分页条件查询
     */
    @RequestMapping("/queryByPage")
    public Map<String, Object> queryByPage(@RequestBody GoodsDTO goodsDTO) {
        return goodsService.queryByPage(goodsDTO);
    }
    /*
     * 根据ID查询多条商品信息
     */
    @RequestMapping("/queryByIds")
    public List<Goods> queryByIds(@RequestBody List<Integer> ids) {
        try {
            Thread.sleep(6000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return goodsService.queryByIds(ids);
    }
}
